package algorithm;

/**
 * 找出数组中第一个不重复的数字,如果没有就返回null
 */
public class FirstDupNum {

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 9, 7, 66, 5, 5, 4, 0, 3, 0, 2, 9, 0, 0, 1, 4};
        System.out.println(handler1(arr));
    }


    public static Integer handler1(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 1; j < arr.length; j++) {
                if(arr[i] == arr[j]){
                    break;
                }
                if(j == arr.length -1){
                    return arr[i];
                }
            }
        }

        return null;
    }

    public static Integer handler(int[] arr) {
        Integer position = null;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length; j++) {
                if (i != j && arr[i] == arr[j]) {
                    position = j;
                    break;
                }
                if (j == arr.length - 1) {
                    position = arr.length;
                }
            }
            if (position == arr.length) {
                return arr[i];
            }
        }
        return null;
    }
}
